import http from '@/utils/http'
import type { PageQuery, PageRes } from '@/types/api'

const BASE_URL = '/generator/test'

/**
 * 测试响应接口
 */
export interface TestResp {
  id: string
  name: string
  age: string
  number: string
  school: string
  createUserString: string
  updateUserString: string
}

/**
 * 测试详情响应接口
 */
export interface TestDetailResp {
  id: string
  name: string
  age: string
  number: string
  school: string
  createUserString: string
  updateUserString: string
}

/**
 * 测试查询条件接口
 */
export interface TestQuery {
  sort?: string[]
}

/**
 * 测试分页查询接口
 */
export interface TestPageQuery extends TestQuery, PageQuery {}

/**
 * 查询测试列表
 */
export function listTest(query: TestPageQuery) {
  return http.get<PageRes<TestResp[]>>(`${BASE_URL}`, query)
}

/**
 * 查询测试详情
 */
export function getTest(id: string) {
  return http.get<TestDetailResp>(`${BASE_URL}/${id}`)
}

/**
 * 新增测试
 */
export function addTest(data: Partial<TestResp>) {
  return http.post(`${BASE_URL}`, data)
}

/**
 * 修改测试
 */
export function updateTest(data: Partial<TestResp>, id: string) {
  return http.put(`${BASE_URL}/${id}`, data)
}

/**
 * 删除测试
 */
export function deleteTest(id: string | string[]) {
  const idParam = Array.isArray(id) ? id.join(',') : id
  return http.del(`${BASE_URL}/${idParam}`)
}

/**
 * 导出测试
 */
export function exportTest(query: TestQuery) {
  return http.download(`${BASE_URL}/export`, { params: query })
}
